/**
  @(#)$Id: AL_File.h 69 2013-10-08 03:03:33Z xiaoting $
  @brief    	AL_File File operations

  @author		$Author: xiaoting $
  @date			$Date: 2013-10-08 11:03:33 +0800 (周二, 08 十月 2013) $
  @version		$Revision: 69 $
  @url			$URL: https://svn.code.sf.net/p/xiaoting/game/trunk/MyProject/AL_StandardLib/groupinc/AL_File.h $
  @header		$Header: https://svn.code.sf.net/p/xiaoting/game/trunk/MyProject/AL_StandardLib/groupinc/AL_File.h 69 2013-10-08 03:03:33Z xiaoting $
 */
#ifndef CXX_AL_FILE_H
#define CXX_AL_FILE_H

#include <fstream>

///////////////////////////////////////////////////////////////////////////
//			AL_File
///////////////////////////////////////////////////////////////////////////
class AL_File
{
public:
	enum FILE_REFERENCE_POS;

	/**
	* Construction
	*
	* @param
	* @return
	*/
	AL_File();

	/**
	* Construction
	*
	* @param		<IN> const NCHAR* cpFilePath
	* @param		<IN> WORD wOpenModel
	static const WORD MODEL_IN			= std::ios::in;			// 0x01, for reading the file does not exist, create (ifstream Open default)
	static const WORD MODEL_OUT			= std::ios::out;		// 0x02, for writing, the file does not exist, to create, if the file already exists, clear the original content (ofstream default Open)
	static const WORD MODEL_ATE			= std::ios::ate;		// 0x04, when the file is opened, the pointer in the file last. Can change the position of the pointer, often used in combination and in, out
	static const WORD MODEL_APP			= std::ios::app;		// 0x08, for writing, the file does not exist, to create, to write new content after the original contents of the file if the file already exists, the total in the final pointer position
	static const WORD MODEL_TRUNC		= std::ios::trunc;		// 0x10, length of the file read and write before first truncated to 0 (default)
	static const WORD MODEL_NOCREATE	= std::ios::_Nocreate;	// 0x20, file does not exist error, often used in combination and in or app
	static const WORD MODEL_NOREPLACE	= std::ios::_Noreplace;	// 0x40, file exists generates an error when used in combination, often and out
	static const WORD MODEL_BINARY		= std::ios::binary;		// 0x80, binary format file
	* @param		<IN> WORD wAccess
	static const WORD ACCESS_ORDINARY	= 0;					// 0: ordinary files, open access
	static const WORD ACCESS_READONLY	= 1;					// 1: read-only file
	static const WORD ACCESS_HIDDEN		= 2;					// 2: hidden file
	static const WORD ACCESS_SYSTEM		= 4;					// 4: System Files
	* @return
	* @note
	* @attention	The default way to open a file to open the binary file reading and writing
					The default file ordinary files, open access
	*/
	AL_File(const NCHAR* cpFilePath, WORD wOpenModel = MODEL_IN|MODEL_OUT|MODEL_BINARY, WORD wOpenAccess = ACCESS_ORDINARY);

	/**
	* Destruction
	*
	* @param
	* @return
	*/
	~AL_File(VOID);

	///////////////////////////////////Open the file///////////////////////////////////////
	/**
	* Open (Open the file)
	*
	* @param		<IN> const NCHAR* cpFilePath
	* @param		<IN> WORD wOpenModel
						static const WORD MODEL_IN			= std::ios::in;			// 0x01, for reading the file does not exist, create (ifstream Open default)
						static const WORD MODEL_OUT			= std::ios::out;		// 0x02, for writing, the file does not exist, to create, if the file already exists, clear the original content (ofstream default Open)
						static const WORD MODEL_ATE			= std::ios::ate;		// 0x04, when the file is opened, the pointer in the file last. Can change the position of the pointer, often used in combination and in, out
						static const WORD MODEL_APP			= std::ios::app;		// 0x08, for writing, the file does not exist, to create, to write new content after the original contents of the file if the file already exists, the total in the final pointer position
						static const WORD MODEL_TRUNC		= std::ios::trunc;		// 0x10, length of the file read and write before first truncated to 0 (default)
						static const WORD MODEL_NOCREATE	= std::ios::_Nocreate;	// 0x20, file does not exist error, often used in combination and in or app
						static const WORD MODEL_NOREPLACE	= std::ios::_Noreplace;	// 0x40, file exists generates an error when used in combination, often and out
						static const WORD MODEL_BINARY		= std::ios::binary;		// 0x80, binary format file
	* @param		<IN> WORD wAccess
						static const WORD ACCESS_ORDINARY	= 0;					// 0: ordinary files, open access
						static const WORD ACCESS_READONLY	= 1;					// 1: read-only file
						static const WORD ACCESS_HIDDEN		= 2;					// 2: hidden file
						static const WORD ACCESS_SYSTEM		= 4;					// 4: System Files
	* @return VOID
	* @note			Note the slash in the path name to dual-write, such as: "\\MyFiles\\ReadMe.txt"
	* @attention	The default way to open a file to open the binary file reading and writing
					The default file ordinary files, open access
	*/
	VOID Open(const NCHAR* cpFilePath, WORD wOpenModel = MODEL_IN|MODEL_OUT|MODEL_BINARY, WORD wOpenAccess = ACCESS_ORDINARY);

////////////////////////////////Check if successfully opened//////////////////////////////////////////
	/**
	* Good (Check if successfully opened)
	*
	* @param VOID
	* @return BOOL
	* @note
	* @attention
	*/
	BOOL Good(VOID);

	/**
	* Fail (Check if successfully opened)
	*
	* @param VOID
	* @return BOOL
	* @note
	* @attention
	*/
	BOOL Fail(VOID);

	/**
	* IsOpen (Check if successfully opened)
	*
	* @param VOID
	* @return BOOL
	* @note			Generally use this method to determine if a file is open successfully
	* @attention
	*/
	BOOL IsOpen(VOID);

/////////////////////////////////Reading and writing binary files/////////////////////////////////////////
	/**
	* Put (Reading and writing binary files)
	*
	* @param		<IN> NCHAR ch
	* @return VOID
	* @note			put () function to write to the stream a character prototype ofstream & put (char ch), 
					the use of relatively simple, such as file1.put ('c'); is to write to the stream a character 'c'.
	* @attention
	*/
	VOID Put(NCHAR ch);
	
	/**
	* Get (Reading and writing binary files)
	*
	* @param		<OUT> NCHAR& ch
	* @return VOID
	* @note			put () corresponds to the form: ifstream & get (char & ch); function is to read a single character 
					from the stream, and the result is stored in the reference ch, if the end of the file, and returns 
					a null character. As file2.get (x); represents a character read from the file, and read characters 
					stored in x.
	* @attention
	*/
	VOID Get(NCHAR& ch);

	/**
	* Get (Reading and writing binary files)
	*
	* @param		<OUT> NCHAR* pStr
	* @param		<IN> DWORD dwGetNum
	* @param		<IN> NCHAR chEndChar
	* @return VOID
	* @note			ifstream & get (char * buf, int num, char delim = '\ n'); this form to read characters into the 
					array pointed to by buf until reads num characters or encounter characters specified by delim, 
					ifdelim this parameter will use the default value of the newline character '\ n'. For example:
					file2.get (str1, 127, 'A') ;/ / read characters from a file into a string str1 terminate when 
					to encounter characters 'A' or read 127 characters.
	* @attention
	*/
	VOID Get(NCHAR* pStr, DWORD dwGetNum, NCHAR chEndChar);


	/**
	* Read (Reading and writing binary files)
	*
	* @param		<OUT> NCHAR* buf
	* @param		<IN> DWORD dwNum
	* @return BOOL
	* @note			Prototype: read (unsigned char * buf, int num); read () num characters to read from the file 
					cache buf points to the end of the file has not been read into the num characters can use member 
					functionsint gcount (); to get the actual number of characters read
	* @attention
	*/
	VOID Read(NCHAR* buf, DWORD dwNum);

	/**
	* Write (Reading and writing binary files)
	*
	* @param		<IN> NCHAR* buf
	* @param		<IN> DWORD dwNum
	* @return BOOL
	* @note			Prototype: write (const unsigned char * buf, int num); write () from buf points to the cache 
					write num characters to the file, it is noteworthy cache type is unsigned char *, may sometimes
					be necessary type conversion.
	* @attention
	*/
	VOID Write(const NCHAR* buf, DWORD dwNum);

	/**
	* Eof End of file is read (Reading and writing binary files)
	*
	* @param VOID
	* @return BOOL
	* @note
	* @attention
	*/
	BOOL Eof(VOID);

	/**
	* Gcount The actual number of bytes read (Reading and writing binary files)
	*
	* @param VOID
	* @return DWORD
	* @note
	* @attention
	*/
	DWORD Gcount(VOID);


	/**
	* Seekg Absolutely move (Reading and writing binary files)
	*
	* @param		<IN> DWORD dwSeek absolute move position
	* @return VOID
	* @note
	* @attention	Input stream operation
	*/
	VOID Seekg(DWORD dwSeek);

	/**
	* Seekg Relatively move (Reading and writing binary files)
	*
	* @param		<IN> DWORD dwSeek relatively move position
	* @param		<IN> FILE_REFERENCE_POS eFileRefPos file reference position
						FILE_REFERENCE_POS_BEG = std::ios :: beg,	// 0: relative to the file header
						FILE_REFERENCE_POS_CUR = std::ios :: cur,	// 1: relative to the current position
						FILE_REFERENCE_POS_END = std::ios :: end,	// 2: relative to the end of the file
	* @return VOID
	* @note
	* @attention	Input stream operation
	*/
	VOID Seekg(DWORD dwSeek, FILE_REFERENCE_POS eFileRefPos);

	/**
	* Tellg Returns the current pointer position (Reading and writing binary files)
	*
	* @param VOID
	* @return VOID
	* @note
	* @attention	Input stream operation
	*/
	VOID Tellg(VOID);

	/**
	* Seekp Absolutely move (Reading and writing binary files)
	*
	* @param		<IN> DWORD dwSeek absolute move position
	* @return VOID
	* @note
	* @attention	Output stream operation
	*/
	VOID Seekp(DWORD dwSeek);

	/**
	* Seekp Relatively move (Reading and writing binary files)
	*
	* @param		<IN> DWORD dwSeek relatively move position
	* @param		<IN> FILE_REFERENCE_POS eFileRefPos file reference position
						FILE_REFERENCE_POS_BEG = std::ios :: beg,	// 0: relative to the file header
						FILE_REFERENCE_POS_CUR = std::ios :: cur,	// 1: relative to the current position
						FILE_REFERENCE_POS_END = std::ios :: end,	// 2: relative to the end of the file
	* @return VOID
	* @note
	* @attention	Output stream operation
	*/
	VOID Seekp(DWORD dwSeek, FILE_REFERENCE_POS eFileRefPos);

	/**
	* Tellp Returns the current pointer position (Reading and writing binary files)
	*
	* @param VOID
	* @return VOID
	* @note
	* @attention	Output stream operation
	*/
	VOID Tellp(VOID);


/////////////////////////////////////Close the file/////////////////////////////////////
	/**
	* Close (Close the file)
	*
	* @param VOID
	* @return VOID
	* @note
	* @attention
	*/
	VOID Close(VOID);

protected:
private:
	/**
	*Copy Construct
	*
	* @param const AL_File& cAL_File
	* @return
	*/
	AL_File(const AL_File& cAL_File);

	/**
	*Assignment
	*
	* @param const AL_File& cAL_File
	* @return AL_File&
	*/
	AL_File &operator =(const AL_File& cAL_File);


public:
	////////////////////////////open model//////////////////////////////////////////////
	static const WORD MODEL_IN			= std::ios::in;			// 0x01, for reading the file does not exist, create (ifstream Open default)
	static const WORD MODEL_OUT			= std::ios::out;		// 0x02, for writing, the file does not exist, to create, if the file already exists, clear the original content (ofstream default Open)
	static const WORD MODEL_ATE			= std::ios::ate;		// 0x04, when the file is opened, the pointer in the file last. Can change the position of the pointer, often used in combination and in, out
	static const WORD MODEL_APP			= std::ios::app;		// 0x08, for writing, the file does not exist, to create, to write new content after the original contents of the file if the file already exists, the total in the final pointer position
	static const WORD MODEL_TRUNC		= std::ios::trunc;		// 0x10, length of the file read and write before first truncated to 0 (default)
	static const WORD MODEL_NOCREATE	= std::ios::_Nocreate;	// 0x20, file does not exist error, often used in combination and in or app
	static const WORD MODEL_NOREPLACE	= std::ios::_Noreplace;	// 0x40, file exists generates an error when used in combination, often and out
	static const WORD MODEL_BINARY		= std::ios::binary;		// 0x80, binary format file

	////////////////////////////open access//////////////////////////////////////////////
	static const WORD ACCESS_ORDINARY	= 0;					// 0: ordinary files, open access
	static const WORD ACCESS_READONLY	= 1;					// 1: read-only file
	static const WORD ACCESS_HIDDEN		= 2;					// 2: hidden file
	static const WORD ACCESS_SYSTEM		= 4;					// 4: System Files

	//////////////////////////////////////////////////////////////////////////
	enum FILE_REFERENCE_POS
	{
		FILE_REFERENCE_POS_BEG = std::ios :: beg,	// 0: relative to the file header
		FILE_REFERENCE_POS_CUR = std::ios :: cur,	// 1: relative to the current position
		FILE_REFERENCE_POS_END = std::ios :: end,	// 2: relative to the end of the file
	};

protected:
private:
	NCHARfstream*	m_pfstream;
};

#endif // CXX_AL_FILE_H
/* EOF */
	